﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsTest0001
{
    public  class DbHelper
    {
        //查

        private static readonly string conString = "server=LAPTOP-47B7TGQ4\\SQLEXPRESS;database=Admin001;uid=sa;pwd=2113144056";

        /// <summary>
        /// 获得表数据
        /// </summary>
        /// <param name="sql">select语句</param>
        /// <returns>表数据</returns>
        public static DataTable GetDataTable(string sql)
        {
           // string conString = "server=LAPTOP-47B7TGQ4\\SQLEXPRESS;database=Admin001;uid=sa;pwd=2113144056";

            SqlConnection sqlConnection = new SqlConnection(conString);

           // string cmdString = "select * from Userso";

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, sqlConnection);

            DataTable dt = new DataTable();

            sqlConnection.Open();

            dataAdapter.Fill(dt);

            return dt;

        }


    }
}
